import JSEncrypt from "jsencrypt/bin/jsencrypt.min";

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey =
  "-----BEGIN PUBLIC KEY-----\n" +
  "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCncXCRyqwMJId8ZW+KaMU7TznM\n" +
  "fTVMgISO8/RJOJez5Lnifojc/4Tdt2B6Vm7gwhRWwMpSEpNWNS0lqwe63I+k1OQ2\n" +
  "8gbQzE5qRpHCzB76crRwovx2IcbzNN5zRpRM4bJjosjlAmeaYCbLmE4v6QmkiBBS\n" +
  "4cFXRK6LfWnw8LPihQIDAQAB\n" +
  "-----END PUBLIC KEY-----";

const privateKey =
  "-----BEGIN PRIVATE KEY-----\n" +
  "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAKdxcJHKrAwkh3xl\n" +
  "b4poxTtPOcx9NUyAhI7z9Ek4l7PkueJ+iNz/hN23YHpWbuDCFFbAylISk1Y1LSWr\n" +
  "B7rcj6TU5DbyBtDMTmpGkcLMHvpytHCi/HYhxvM03nNGlEzhsmOiyOUCZ5pgJsuY\n" +
  "Ti/pCaSIEFLhwVdErot9afDws+KFAgMBAAECgYEAm3CkxsL1uoQCvolP5ZZjWi6v\n" +
  "AlVNsEoyRJ7VrU97DQYNReSfW0Fdb5H3XzpzzfR9exeX+l7CJipRUgGWuHJeaW5U\n" +
  "q3kp3IQwMaEt8PAdTMqRctog+F/pNC9gPcz4SIXCL9JlPuSEtgcwrVT7g0zcnN7r\n" +
  "T5bm7mFIzMCuJY+/21UCQQDZkcz7I3u9eMpBiI1n/PwZK59z2MStv6jNFlCZ0vgd\n" +
  "d1gY/eg3+6hRieCKKuc5VDj9uXvfDRsPe9qLlixnW4zfAkEAxQT9oE1ZjTwPqhTV\n" +
  "lCSh26kVzqI3WduJiYXF52qJ1M1i+51G0NgvdUbacbQ/IPmvTiIDPx4qgj8s9+Qg\n" +
  "cb3ZGwJASo8vmuTnE+BgF6MvKnLFBe8wHqgrhouG0nmSN5TX2Gk8tJvWx9CjNwYz\n" +
  "/8WCJeBaA4FcFO1N17mPBIT7RJRYKwJAaL5AgKrew0F9KnUtHzdifb+lAlgniTQ4\n" +
  "KM7f6iov4NzYlOCGt51Xjcf/dpfXQBa+ZpGanEHTY69mntu/i/jcpQJBAKnEwLb3\n" +
  "PGhjJ5FlvaQ17D/+ccedB887UkKYMYmrUj7zpjt9IU8/rMyZkgWLwZMN3+lnzWQH\n" +
  "DgRs4LZ1EG0X5eI=\n" +
  "-----END PRIVATE KEY-----";

export function encrypt(txt) {
  const encryptor = new JSEncrypt();
  encryptor.setPublicKey(publicKey);
  return encryptor.encrypt(txt);
}

export function decrypt(txt) {
  const encryptor = new JSEncrypt();
  encryptor.setPrivateKey(privateKey);
  return encryptor.decrypt(txt);
}
